<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>路书</title>
	<style type="text/css">
		body, html{width: 100%;height: 78%;margin:0;font-family:"微软雅黑";}
		#map_canvas{width:100%;height:500px;}
		#result {width:100%}
	</style>
	<script src="//api.map.baidu.com/api?v=2.0&ak=W3XhPbGAYXGNabsgBawyo1GFNbSi20Bl"></script>
	<script type="text/javascript" src="//api.map.baidu.com/library/LuShu/1.2/src/LuShu_min.js"></script>
	<script type="text/javascript" src="../../res/js/jquery-3.4.1.min.js"></script>
	<script>
		var variateArray;
		/**
		 得到地址栏的参数
		 */
		function getQueryString(name){
			var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if(r!=null)return  unescape(r[2]); return null;
		}
		$(function(){
			var $=jQuery.noConflict();
			var  expressNumber1 = getQueryString("id");
			window.localStorage.setItem("expressNumber1",expressNumber1);
			if(expressNumber1){
				$.ajax({
					url: '/expressage/findExpressageInfoReturn',
					data: {ExpressNumber:expressNumber1},
					dataType: 'json',
					type: 'POST',
					success: function (obj) {
						var one = obj[1]+','+obj[0];
						ditu(one);
					},
					error: function () {
					}
				});
			}
		})
	</script>
</head>
<body>
	<div id="map_canvas"></div>
	<div id="result"></div>
<!--	<button id="run">开始</button>-->
<!--	<button id="stop">停止</button>-->
<!--	<button id="pause">暂停</button>-->
<!--	<button id="hide">隐藏信息窗口</button>-->
<!--	<button id="show">展示信息窗口</button>-->
	<iframe src="orderRetrun/pages/timerShaftReturn.html" style="width: 99.6%; height: 54%;  "   ></iframe>
	<script>

	//构建一个简单的地图
	var map = new BMap.Map('map_canvas');
	map.enableScrollWheelZoom();	
	map.centerAndZoom(new BMap.Point(116.404, 39.915), 13);
	var lushu;
	var drv = new BMap.DrivingRoute('西安', {
	    onSearchComplete: function(res) {
	        if (drv.getStatus() == BMAP_STATUS_SUCCESS) {
	            var plan = res.getPlan(0);
	            var arrPois =[];
	            for(var j=0;j<plan.getNumRoutes();j++){
	                var route = plan.getRoute(j);
	                arrPois= arrPois.concat(route.getPath());
	            }
				//修改线条
	            map.addOverlay(new BMap.Polyline(arrPois, {strokeColor: 'red'}));
	            map.setViewport(arrPois);

	            lushu = new BMapLib.LuShu(map,arrPois,{
	            defaultContent:"",//"从天安门到百度大厦"
	            autoView:true,//是否开启自动视野调整，如果开启那么路书在运动过程中会根据视野自动调整
	            icon  : new BMap.Icon('/images/vehicle.png', new BMap.Size(52,26),{anchor : new BMap.Size(27, 13)}),
	            speed: 56000,
	            enableRotation:true});
	        }
	    }
	});


	function ditu(one){
		var variateArray = [];
		var text = one;
		var variateArray2 = text.split(",");//逗号是分隔符
		var i = 0;
		for(i=0;i<variateArray2.length;i++){
			var localSearch = new BMap.LocalSearch(map);
			localSearch.enableAutoViewport(); //允许自动调节窗体大小

			localSearch.setSearchCompleteCallback(function (searchResult) {
				//对象
				var poi = searchResult.getPoi(0);
				variateArray.push(poi.point.lng + "," + poi.point.lat);
				ss(variateArray[0],variateArray[1]);
				// 实例化一个驾车导航用来生成路线
			});
			localSearch.search(variateArray2[i])
		}
		var io = "";
		function ss(s1,s2){
			if(s2!=undefined){
				a = s1.substr(0,s1.indexOf(","));
				b = s1.substr(s1.indexOf(",")+1,s1.length);

				c = s2.split(",");
				var myP1 = new BMap.Point(a,b);    //起点
				var myP2 = new BMap.Point(c[0],c[1]);    //终点
				drv.search(myP1, myP2);
			}
		}
	}

	//绑定事件
	$("run").onclick = function(){
		lushu.start();
	}
	$("stop").onclick = function(){
		lushu.stop();
	}
	$("pause").onclick = function(){
		lushu.pause();
	}
	$("hide").onclick = function(){
		lushu.hideInfoWindow();
	}
	$("show").onclick = function(){
		lushu.showInfoWindow();
	}
	function $(element){
		return document.getElementById(element);
	}
</script>
</body>
</html>
